<template>
<div>
    <h2>借款项目列表</h2>
    <BorrowCommon v-slot="info">
        <a href="#" @click="DeleteBorrow(info.id)">删除</a>
        &nbsp;
        <a href="#" @click="UpdateBorrow(info.id)">修改</a>
    </BorrowCommon>
</div>
</template>


<script setup lang="ts">
import axios from 'axios';
import { useRouter } from 'vue-router';
import BorrowCommon from '../BorrowMoney/BorrowCommon.vue'

//创建路由实例
const router=useRouter();

//完成删除功能
const DeleteBorrow=(Bid:number)=>{
    if(confirm('确认删除吗？')){
        axios.delete('https://localhost:44321/api/Borrows/DelBorrowMoney',
            {
                params:{
                    Bid:Bid
                }
            }
        )
        .then(res=>{
            if(res.data>0){
                alert('删除成功');
                location.reload();
            }
            else{
                alert('删除失败');
            }
        })
        .catch(err=>{
            console.log(err);
        })
    }
}   

//完成跳转到修改页面
const UpdateBorrow=(Bid:number)=>{
    router.push({
        name:'EditBorrowMoney',
        params:{
            Bid:Bid
        }
    })
}
</script>